package com.gwz.wxtime.chessboard.entity;

import java.util.Comparator;

//自定义比较器
public class MyComparator implements Comparator<Puke> {

    @Override
    public int compare(Puke pu1, Puke pu2) {
        MyComparator myComparator = new MyComparator();
        //比较两个数字的大小
        //num正数pu1 > pu2  num=0 pu1 > pu2 num负数 pu1 < pu2

        int num1 = pu1.getNum();
        int num2 = pu2.getNum();

        int num = num1 - num2;
        //如果两个牌数字相同，则进行花色比较
        if (num == 0) {
            //黑桃>红桃>梅花>方块
            if (myComparator.compareToFlower(pu1) > myComparator.compareToFlower(pu2)) {
                num = -1;
            } else if (myComparator.compareToFlower(pu1) < myComparator.compareToFlower(pu2)) {
                num = 1;
            }

        }
        return num;
    }

    //定义比较规则
    public int compareToFlower(Puke pk1) {
        int num1 = 0;
        switch (pk1.getHuase()) {
            case 1:
                num1 = 4;
                break;
            case 2:
                num1 = 3;
                break;
            case 3:
                num1 = 2;
                break;
            case 4:
                num1 = 1;
                break;
            default:
                num1 = -1;
                break;
        }

        return num1;
    }
}